﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GeostatisticalTool.Classes;

namespace GeostatisticalTool.Forms
{
    public partial class ParameterDeterministic : UserControl
    {
        private string type;
        private string method;
        private double value;

        private ParameterInterpolator par;



        public event EventHandler ChangedParameters;
        protected virtual void OnChangedParameters(EventArgs e)
        {
            if (ChangedParameters != null)
                ChangedParameters(this, e);
        }


        public double Value
        {
            get { return this.value; }
        }

        public void SetParameter(ParameterInterpolator par)
        {
            this.par = par;
            this.value = par.Value;
            this.type = par.Type;
            this.uxValue.Text = this.value.ToString();
            if (par.Type!= null)
            this.uxMethod.Text = par.Type;
        }

        public ParameterInterpolator GetParameter()
        {
            this.par.Value = this.value;
            this.par.Type = this.type;
            this.par.Index = this.uxMethod.SelectedIndex;
            return this.par;
        }

        public void SetType(string value)
        {
            this.type = value;
        }

        public void  SetMethod(string value)
        {

           this.method = value;
            if (this.method == "IDW")
            {

                uxlabel.Visible = true;
                uxValue.Visible = true;
                uxlabel.Text = "Power";
                //uxValue.Text = "2";
                uxLabelMethod.Visible = false;
                uxMethod.Visible = false;
            }

            if (this.method == "RBF")
            {
                uxlabel.Text = "Factor";
                
                uxLabelMethod.Visible = true;
                uxMethod.Visible = true;
                uxlabel.Visible = true;
                uxValue.Visible = true;
            }

            if (this.method == "local")
            {
                uxlabel.Text = "Polynomial Order";
                //uxValue.Text = "2";
                uxLabelMethod.Visible = false;
                uxMethod.Visible = false;
            }

            if (this.method == "Global")
            {
                uxlabel.Visible = false;
                uxValue.Visible = false;
                uxLabelMethod.Text = "Polynomial Order";

                //uxValue.Text = "2";
                uxLabelMethod.Visible = true;
                uxMethod.Visible = true;
                uxMethod.Items.Clear();

                uxMethod.Items.Add("Constant");
                uxMethod.Items.Add("First");
                uxMethod.Items.Add("Second");
                uxMethod.Items.Add("Third");
                uxMethod.SelectedIndex = 1;
            }


        }

        public int GetIndexSelected()
        {
            return uxMethod.SelectedIndex;

        }

        public void SetIndexSelected(int v)
        {
            uxMethod.SelectedIndex=v;

        }

        public string GetMethod()
        {
            return this.method;
        }

        public void EnableApply(bool value)
        {
            uxApply.Enabled = value;
        }

        public ParameterDeterministic()
        {
            InitializeComponent();
            par = new ParameterInterpolator();

        }

        private void uxValue_TextChanged(object sender, EventArgs e)
        {
            if (Validator.IsDouble(uxValue))
            {
                uxApply.Enabled = true;
                this.value = Convert.ToDouble(uxValue.Text);
            }
            else
                uxApply.Enabled = false;
        }

        private void uxApply_Click(object sender, EventArgs e)
        {
            OnChangedParameters(EventArgs.Empty);
        }

        private void uxMethod_SelectedIndexChanged(object sender, EventArgs e)
        {
            uxApply.Enabled = true;
        }

        private void ParameterDeterministic_Load(object sender, EventArgs e)
        {

        }


    }
}
